public class Solution {
    public int maxProfit(int[] prices, int fee) {
        int len = prices.length;

        int[] f = new int[len];//买入
        int[] g = new int[len];//卖出

        f[0] -= prices[0];

        for (int i = 1; i < len; i++) {
            f[i] = Math.max(f[i - 1], g[i - 1] - prices[i]);
            g[i] = Math.max(f[i - 1] + prices[i] - fee, g[i - 1]);
        }

        return Math.max(f[len - 1], g[len - 1]);
    }
}
